package com.zmsk.zmio.handler;

import android.content.Context;

import com.zmsk.zmio.inter.IIOHandler;
import com.zmsk.zmio.ysm8.IOControlUtils;

import java.io.IOException;

public class YSPathHandler implements IIOHandler {
    @Override
    public void initIOControl(Context context) {

    }

    @Override
    public void stopIOControl(Context context) {

    }

    @Override
    public void noticeGateOpen(Context context, String idNumber) {
        writeGPIOFile("/sys/devices/misc_power_en.23/key_out2", "1");
    }

    @Override
    public void noticeGateClose(Context context) {
        writeGPIOFile("/sys/devices/misc_power_en.23/key_out2", "0");
    }

    @Override
    public void noticeWhiteLedOn(Context context) {
        writeGPIOFile("/sys/devices/misc_power_en.23/key_out1", "1");
    }

    @Override
    public void noticeWhiteLedOff(Context context) {
        writeGPIOFile("/sys/devices/misc_power_en.23/key_out1", "0");
    }

    @Override
    public void noticeInfraredLedOn(Context context) {
        writeGPIOFile("/sys/devices/misc_power_en.23/key_out3", "1");
    }

    @Override
    public void noticeInfraredLedOff(Context context) {
        writeGPIOFile("/sys/devices/misc_power_en.23/key_out3", "0");
    }

    @Override
    public void noticeRedLedOn(Context context) {

    }

    @Override
    public void noticeRedLedOff(Context context) {

    }

    @Override
    public void noticeGreenLedOn(Context context) {

    }

    @Override
    public void noticeGreenLedOff(Context context) {

    }

    @Override
    public void handleSlientInstall(String path) {

    }

    private static void writeGPIOFile(String path, String value) {
        try {
            IOControlUtils.writeIOFile(value, path);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}
